<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />

		<style type="text/css">
			/*下面两项是重置muicss的输入框label和input之间的宽比率*/
			
			.mui-input-row label {
				width: 20%;
			}
			
			.mui-input-row label~input {
				width: 80%;
			}
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav own-main-background-color">
			<button type="button" class="mui-action-back mui-btn  mui-btn-link mui-pull-left own-button">
			<!--<span class="mui-action-back mui-icon mui-icon-left-nav own-left-nav-color"></span>-->
			<span class="own-left-nav-color">取消</span>
		</button>
			<h1 class="mui-title">登录</h1>
		</header>

		<div class="mui-content">
			<div style="margin-top: 30px; text-align: center;">
				<img src="../img/96-logo.png" />
			</div>
			<div class="mui-card" style="margin-top: 20px;">
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label><span class="mui-icon iconfont icon-zhanghao"></span></label>
						<input type="text" class="mui-input-clear" value="" placeholder="请输入手机号" id="tell">
					</div>
					<div class="mui-input-row">
						<label><span class="mui-icon iconfont icon-mimaxiugai"></span></label>
						<input type="password" class="mui-input-clear" value="" placeholder="请输入密码" id="pass">
					</div>
				</form>
			</div>
			<div class="mui-button-row" style="margin: 10px 15px;">
				<button id="loginBtn" type="button" class="mui-btn mui-btn-green own-btn-green mui-btn-block " style="padding: 5px 0px;">登录</button>
			</div>
			<div class="mui-button-row" style="padding-top: 0px;">
				<button id="register" type="button" class="mui-btn mui-btn-link own-main-color own-font-size" style="padding-top: 0px; margin-right: 60px; ">快速注册</button>
				<button id="repsd" type="button" class="mui-btn mui-btn-link own-font-size" style="padding-top: 0px; margin-left: 60px; color: #FF6A6A;">忘记密码</button>
			</div>

		</div>
		<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
		<script src="../js/mui.min.js" charset="UTF-8"></script>
		<script src="../js/own.js" charset="UTF-8"></script>
		<script src="../js/ajax.js" charset="UTF-8"></script>
		<script type="text/javascript" charset="UTF-8">
			mui.init({
				swipeBack: true
			});
			var account;
			var psd;
			var login;
			var register;
			var repsd;
			var loginWebview;
			mui.plusReady(function() {
				
				/*localStorage.setItem("username",document.getElementById("tell").value);
				localStorage.setItem("password",document.getElementById("pass").value); 
				
				localStorage.getItem("username");
				localStorage.getItem("password"); */
				
				
				 var Id = localStorage.getItem("tell"); 
            if(Id != null)
            { 
                document.getElementById("tell").value = Id; 
                document.getElementById("pass").value = localStorage.getItem("pass"); 
}
            var loginBtn=document.getElementById("loginBtn");
           		
           		loginBtn.addEventListener("tap",function(){
            	
            		var idid = document.getElementById("tell").value; 
                    var pwdpwd = document.getElementById("pass").value; 
                    localStorage.setItem("tell", idid); 
                    localStorage.setItem("pass", pwdpwd);  
            }); 
            		
				
				
				
				
				account = document.querySelector('input[type="text"]');
				psd = document.querySelector('input[type="password"]');
				login = document.getElementById('loginBtn');
				register = document.getElementById('register');
				repsd = document.getElementById('repsd');
				loginWebview = plus.webview.currentWebview();
				//检测本地的登录过的账号。
				if(localStorage.getItem('account')) {
					account.value = localStorage.getItem('account');
				}
				//登陆的点击事件
				login.addEventListener('tap', function() {
					//将两个数据存放起来，第一个是等出之后删除，第二个只要登录之后就会记录保存

					var d = {};
					d.account = document.getElementById("tell").value;
					d.password = document.getElementById("pass").value;
					mui.ajax(url + 'rest/loginSrv', {

						data: d,

						dataType: 'json', //服务器返回json格式数据

						type: 'POST', //HTTP请求类型

						timeout: 10000, //超时时间设置为10秒；

						//headers:{'Content-Type':'application/json'},	              

						success: function(result) {

							//alert(result.status+result.msg);

							//result = JSON.parse(result);

							//alert(result.status+result.msg);

							if(result.status != '0') {
								mui.alert("账号或者密码错误");

							} else {
								localStorage.setItem('user', true);

								mui.back();
								mui.toast('登录成功');
								//添加事件接收close事件，并且要判断是否已经登录成功，然后页面close，因为login页面是预先加载的页面
								//在这里向需要的页面发送消息事件通知已经登录做响应的处理
								loginWebview.addEventListener('hide', function() {
									
					
									mui.each(plus.webview.all(), function(index, item) {

											console.log(item.id)
										})
										//alert(666);
									plus.storage.setItem("accountId", result.id);
									plus.storage.setItem("user", d.account);

									plus.storage.setItem("passWord", d.password);
									plus.storage.setItem("tokenCode", result.token);
									plus.storage.setItem("userName", result.name);
									//var wallet = result.wallet;

									plus.storage.setItem("nickName", result.data.nickName);
									plus.storage.setItem("sex", result.data.sex);
									//alert(result.data.name);
									//alert(result.name);

									plus.storage.setItem("balance", result.data.wallet.balance + "");
									plus.storage.setItem("publicMoney", result.data.wallet.publicMoney + "");
									plus.storage.setItem("level", result.data.wallet.level);

								
									plus.storage.setItem("userAddrList", JSON.stringify(result.data.userAddresses));

									//var cartwebview = plus.webview.getWebviewById('barItem/cart.html');

									var cartwebview = plus.webview.getWebviewById('barItem/cart.html');
									
									
									var minewebview = plus.webview.getWebviewById('barItem/mine.html');
						//var xinyuandanwebview = plus.webview.getWebviewById('barItem/wishList.html');
						mui.fire(cartwebview, 'loginSuccess', {});
						mui.fire(minewebview, 'loginSuccess', {});
						//mui.fire(xinyuandanwebview, 'loginSuccess', {});
						loginWebview.close();

								}, false);

							}

							//服务器返回响应，根据响应结果，分析是否登录成功

						},

						error: function(xhr, type, errorThrown) {

							//异常处理；

							mui.alert("登录异常")

						}

					});

				

				}, false);
				//注册按钮的点击事件
				register.addEventListener('tap', function() {
					pushWebView({
						webType: 'newWebview_First',
						id: 'mine/register-needtem.html',
						href: 'mine/register-needtem.html',
						aniShow: getaniShow(),
						title: "注册",
						isBars: false,
						barsIcon: '',
						extendOptions: {}
					})
				}, false);
				//注册按钮的点击事件
				repsd.addEventListener('tap', function() {
					pushWebView({
						webType: 'newWebview_First',
						id: 'mine/forget-psd-needtem.html',
						href: 'mine/forget-psd-needtem.html',
						aniShow: getaniShow(),
						title: "忘记密码",
						isBars: false,
						barsIcon: '',
						extendOptions: {}
					})
				}, false);
			});
		</script>
	</body>

</html>